package emergency.network;

import android.util.Log;

import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.whu.zj.MyApplication;
import com.whu.zj.R;
import com.whu.zj.VolleySingleton;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import inter.Delegate;

/**
 * 预警处理
 * Created by Administrator on 2016/4/8.
 */
public class DealEmergency {

    Delegate delegate;
    StringRequest stringRequest;
    String alertAlertId;
    String recordTime;
    String disposealertname;

    public void setDelegate(Delegate delegate) {
        this.delegate = delegate;
    }

    public void setAlertAlertId(String alertAlertId) {
        this.alertAlertId = alertAlertId;
    }

    public void setRecordTime(String recordTime) {
        this.recordTime = recordTime;
    }

    public void setDisposealertname(String disposealertname) {
        this.disposealertname = disposealertname;
    }

    public void get() {
        String ip = MyApplication.share().getResources().getString(R.string.IP_zj);
        String url = "http://" + ip +  "/UpdateAlertRecord?alertId="+ alertAlertId + "&recordTime=" + recordTime + "&disposealertname=" + disposealertname;
        stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.i("预警数据", response);
                if (delegate != null)
                    delegate.onResponse(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (delegate != null)
                    delegate.onErrorResponse(error);
            }
        });
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }

    public void cancel()
    {
        if (!stringRequest.isCanceled())
            stringRequest.cancel();
    }
}
